<?php


namespace Hilaoyu\LaravelExtend\Services\Files;
use Hilaoyu\LaravelExtend\Model;
use Illuminate\Support\Carbon;


abstract class FileAppsModelAbstract extends Model
{

    protected $table = 'file_apps';
    protected $fillable = [
        'name',
        'secret',
        'domain',
        'introduction',
        'logo',
        'status',
    ];

    protected $casts = [
        'domain'=>'json'
    ];

    protected $appends = [
        'status_name'
    ];


    public function getValidationRules()
    {

        $rules = [
            'name' => 'required|string|unique:' . static::getTableCon() . ',name,' . $this->getOriginalKey() . ',' . static::getPkName(),
            'secret' => 'required|string' ,
        ];

        return $rules;
    }

    public function getValidationMessages()
    {
        return [
            'name.required' => '名称必填',
            'secret.required' => '密钥必填',
        ];
    }

    public function getStatusNameAttribute()
    {
        $status = $this->getAttribute('status');
        return '1' == $status ? '启用' : '禁用';
    }


}
